﻿using EFMYSQLTest.DB;
using EFMYSQLTest.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFMYSQLTest.Service
{
    public class UserService : IUserService
    {
        private readonly IRepository<User> userRepository;
        public UserService(IRepository<User> userRepository)
        {
            this.userRepository = userRepository;
        }

        public User FindByName(string name)
        {
            return userRepository.Table.FirstOrDefault(p => p.Name == name);
        }

        public void Add()
        {
            var user = new User {
                 Name="aa",
                 Password="bb",
                 CreatedTime=DateTime.Now
            };

            userRepository.Insert(user);

        }

        public IList<User> GetList()
        {
            return userRepository.Table.OrderBy(p => p.Id).Take(50).ToList();
        }
    }
}
